package com.xique.park.controller.auto;

import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.xique.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.ParkGarage;
import com.xique.park.service.service.IParkGarageService;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.page.TableDataInfo;

/**
 * 车库Controller
 *
 * @author xique
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/garage")
@Deprecated
public class ParkGarageController extends BaseController {
    @Autowired
    private IParkGarageService parkGarageService;

    /**
     * 查询车库列表
     */
    @PreAuthorize(hasPermi = "park:garage:list")
    @GetMapping("/list")
    public TableDataInfo list(ParkGarage parkGarage) {
        startPage();
        List<ParkGarage> list = parkGarageService.selectParkGarageList(SecurityUtils.getParkId(), parkGarage);
        return getDataTable(list);
    }

    /**
     * 导出车库列表
     */
    @PreAuthorize(hasPermi = "park:garage:export")
    @Log(title = "车库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkGarage parkGarage) throws IOException {
        List<ParkGarage> list = parkGarageService.selectParkGarageList(SecurityUtils.getParkId(), parkGarage);
        ExcelUtil<ParkGarage> util = new ExcelUtil<>(ParkGarage.class);
        util.exportExcel(response, list, "车库数据");
    }

    /**
     * 获取车库详细信息
     */
    @PreAuthorize(hasPermi = "park:garage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(parkGarageService.selectParkGarageById(id));
    }

    /**
     * 新增车库
     */
    @PreAuthorize(hasPermi = "park:garage:add")
    @Log(title = "车库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkGarage parkGarage) {
        return toAjax(parkGarageService.insertParkGarage(parkGarage));
    }

    /**
     * 修改车库
     */
    @PreAuthorize(hasPermi = "park:garage:edit")
    @Log(title = "车库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkGarage parkGarage) {
        return toAjax(parkGarageService.updateParkGarage(parkGarage));
    }

    /**
     * 删除车库
     */
    @PreAuthorize(hasPermi = "park:garage:remove")
    @Log(title = "车库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        List<Long> idList = Arrays.asList(ids);
        return toAjax(parkGarageService.deleteParkGarageByIds(idList));
    }
}
